#include "gamepanel.h"

const int GamePanel::playervsai=150;
const int GamePanel::aivsai=151;
const int GamePanel::greedybyfront=152;
const int GamePanel::greedybyback=153;
const int GamePanel::slow=154;
const int GamePanel::medium=155;
const int GamePanel::fast=156;
const int GamePanel::playerturn=157;
const int GamePanel::aiturn=158;
const int GamePanel::ai1turn=159;
const int GamePanel::ai2turn=160;
const int GamePanel::blackturn=161;
const int GamePanel::whiteturn=162;


GamePanel::GamePanel(wxFrame*frame,int id,bool isnewgame,wxString sourcefile,int boardsize,
          int gametype,wxString playername,int greedytype,int greedytype1,int greedytype2,int gamespeed)
 : wxPanel(frame,id,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL,wxT("Game Panel"))
{
    this->gametype=gametype;
    this->boardsize=boardsize;
    int i;
    arr = (int**)malloc(boardsize*sizeof(int));
    for(i=0;i<boardsize;++i)
    {
        arr[i] = (int*)malloc(boardsize*sizeof(int));
    }

    wxPuts(wxT("d1\n"));

    //Jika dipilih newgame
    if (isnewgame)
    {
        wxPuts(wxT("d2\n"));
        typeturn=blackturn;
        if (boardsize==8)
        {
            arr[0][0]=Dam::ID_WHITE_EMPTY;arr[0][1]=Dam::ID_WHITE_DAM;arr[0][2]=Dam::ID_WHITE_EMPTY;arr[0][3]=Dam::ID_WHITE_DAM;arr[0][4]=Dam::ID_WHITE_EMPTY;arr[0][5]=Dam::ID_WHITE_DAM;arr[0][6]=Dam::ID_WHITE_EMPTY;arr[0][7]=Dam::ID_WHITE_DAM;
            arr[1][0]=Dam::ID_WHITE_DAM;arr[1][1]=Dam::ID_WHITE_EMPTY;arr[1][2]=Dam::ID_WHITE_DAM;arr[1][3]=Dam::ID_WHITE_EMPTY;arr[1][4]=Dam::ID_WHITE_DAM;arr[1][5]=Dam::ID_WHITE_EMPTY;arr[1][6]=Dam::ID_WHITE_DAM;arr[1][7]=Dam::ID_WHITE_EMPTY;
            arr[2][0]=Dam::ID_WHITE_EMPTY;arr[2][1]=Dam::ID_WHITE_DAM;arr[2][2]=Dam::ID_WHITE_EMPTY;arr[2][3]=Dam::ID_WHITE_DAM;arr[2][4]=Dam::ID_WHITE_EMPTY;arr[2][5]=Dam::ID_WHITE_DAM;arr[2][6]=Dam::ID_WHITE_EMPTY;arr[2][7]=Dam::ID_WHITE_DAM;
            arr[3][0]=Dam::ID_BLACK_EMPTY;arr[3][1]=Dam::ID_WHITE_EMPTY;arr[3][2]=Dam::ID_BLACK_EMPTY;arr[3][3]=Dam::ID_WHITE_EMPTY;arr[3][4]=Dam::ID_BLACK_EMPTY;arr[3][5]=Dam::ID_WHITE_EMPTY;arr[3][6]=Dam::ID_BLACK_EMPTY;arr[3][7]=Dam::ID_WHITE_EMPTY;
            arr[4][0]=Dam::ID_WHITE_EMPTY;arr[4][1]=Dam::ID_BLACK_EMPTY;arr[4][2]=Dam::ID_WHITE_EMPTY;arr[4][3]=Dam::ID_BLACK_EMPTY;arr[4][4]=Dam::ID_WHITE_EMPTY;arr[4][5]=Dam::ID_BLACK_EMPTY;arr[4][6]=Dam::ID_WHITE_EMPTY;arr[4][7]=Dam::ID_BLACK_EMPTY;
            arr[5][0]=Dam::ID_BLACK_DAM;arr[5][1]=Dam::ID_WHITE_EMPTY;arr[5][2]=Dam::ID_BLACK_DAM;arr[5][3]=Dam::ID_WHITE_EMPTY;arr[5][4]=Dam::ID_BLACK_DAM;arr[5][5]=Dam::ID_WHITE_EMPTY;arr[5][6]=Dam::ID_BLACK_DAM;arr[5][7]=Dam::ID_WHITE_EMPTY;
            arr[6][0]=Dam::ID_WHITE_EMPTY;arr[6][1]=Dam::ID_BLACK_DAM;arr[6][2]=Dam::ID_WHITE_EMPTY;arr[6][3]=Dam::ID_BLACK_DAM;arr[6][4]=Dam::ID_WHITE_EMPTY;arr[6][5]=Dam::ID_BLACK_DAM;arr[6][6]=Dam::ID_WHITE_EMPTY;arr[6][7]=Dam::ID_BLACK_DAM;
            arr[7][0]=Dam::ID_BLACK_DAM;arr[7][1]=Dam::ID_WHITE_EMPTY;arr[7][2]=Dam::ID_BLACK_DAM;arr[7][3]=Dam::ID_WHITE_EMPTY;arr[7][4]=Dam::ID_BLACK_DAM;arr[7][5]=Dam::ID_WHITE_EMPTY;arr[7][6]=Dam::ID_BLACK_DAM;arr[7][7]=Dam::ID_WHITE_EMPTY;
        }
        else if (boardsize==10)
        {
            wxPuts(wxT("d3\n"));
            arr[0][0]=Dam::ID_WHITE_EMPTY;arr[0][1]=Dam::ID_WHITE_DAM;arr[0][2]=Dam::ID_WHITE_EMPTY;arr[0][3]=Dam::ID_WHITE_DAM;arr[0][4]=Dam::ID_WHITE_EMPTY;arr[0][5]=Dam::ID_WHITE_DAM;arr[0][6]=Dam::ID_WHITE_EMPTY;arr[0][7]=Dam::ID_WHITE_DAM;arr[0][8]=Dam::ID_WHITE_EMPTY;arr[0][9]=Dam::ID_WHITE_DAM;
            arr[1][0]=Dam::ID_WHITE_DAM;arr[1][1]=Dam::ID_WHITE_EMPTY;arr[1][2]=Dam::ID_WHITE_DAM;arr[1][3]=Dam::ID_WHITE_EMPTY;arr[1][4]=Dam::ID_WHITE_DAM;arr[1][5]=Dam::ID_WHITE_EMPTY;arr[1][6]=Dam::ID_WHITE_DAM;arr[1][7]=Dam::ID_WHITE_EMPTY;arr[1][8]=Dam::ID_WHITE_DAM;arr[1][9]=Dam::ID_WHITE_EMPTY;
            arr[2][0]=Dam::ID_WHITE_EMPTY;arr[2][1]=Dam::ID_WHITE_DAM;arr[2][2]=Dam::ID_WHITE_EMPTY;arr[2][3]=Dam::ID_WHITE_DAM;arr[2][4]=Dam::ID_WHITE_EMPTY;arr[2][5]=Dam::ID_WHITE_DAM;arr[2][6]=Dam::ID_WHITE_EMPTY;arr[2][7]=Dam::ID_WHITE_DAM;arr[2][8]=Dam::ID_WHITE_EMPTY;arr[2][9]=Dam::ID_WHITE_DAM;
            arr[3][0]=Dam::ID_WHITE_DAM;arr[3][1]=Dam::ID_WHITE_EMPTY;arr[3][2]=Dam::ID_WHITE_DAM;arr[3][3]=Dam::ID_WHITE_EMPTY;arr[3][4]=Dam::ID_WHITE_DAM;arr[3][5]=Dam::ID_WHITE_EMPTY;arr[3][6]=Dam::ID_WHITE_DAM;arr[3][7]=Dam::ID_WHITE_EMPTY;arr[3][8]=Dam::ID_WHITE_DAM;arr[3][9]=Dam::ID_WHITE_EMPTY;
            arr[4][0]=Dam::ID_WHITE_EMPTY;arr[4][1]=Dam::ID_BLACK_EMPTY;arr[4][2]=Dam::ID_WHITE_EMPTY;arr[4][3]=Dam::ID_BLACK_EMPTY;arr[4][4]=Dam::ID_WHITE_EMPTY;arr[4][5]=Dam::ID_BLACK_EMPTY;arr[4][6]=Dam::ID_WHITE_EMPTY;arr[4][7]=Dam::ID_BLACK_EMPTY;arr[4][8]=Dam::ID_WHITE_EMPTY;arr[4][9]=Dam::ID_BLACK_EMPTY;
            arr[5][0]=Dam::ID_BLACK_EMPTY;arr[5][1]=Dam::ID_WHITE_EMPTY;arr[5][2]=Dam::ID_BLACK_EMPTY;arr[5][3]=Dam::ID_WHITE_EMPTY;arr[5][4]=Dam::ID_BLACK_EMPTY;arr[5][5]=Dam::ID_WHITE_EMPTY;arr[5][6]=Dam::ID_BLACK_EMPTY;arr[5][7]=Dam::ID_WHITE_EMPTY;arr[5][8]=Dam::ID_WHITE_DAM;arr[5][9]=Dam::ID_WHITE_EMPTY;
            arr[6][0]=Dam::ID_WHITE_EMPTY;arr[6][1]=Dam::ID_BLACK_DAM;arr[6][2]=Dam::ID_WHITE_EMPTY;arr[6][3]=Dam::ID_BLACK_DAM;arr[6][4]=Dam::ID_WHITE_EMPTY;arr[6][5]=Dam::ID_BLACK_DAM;arr[6][6]=Dam::ID_WHITE_EMPTY;arr[6][7]=Dam::ID_BLACK_DAM;arr[6][8]=Dam::ID_WHITE_EMPTY;arr[6][9]=Dam::ID_BLACK_DAM;
            arr[7][0]=Dam::ID_BLACK_DAM;arr[7][1]=Dam::ID_WHITE_EMPTY;arr[7][2]=Dam::ID_BLACK_DAM;arr[7][3]=Dam::ID_WHITE_EMPTY;arr[7][4]=Dam::ID_BLACK_DAM;arr[7][5]=Dam::ID_WHITE_EMPTY;arr[7][6]=Dam::ID_BLACK_DAM;arr[7][7]=Dam::ID_WHITE_EMPTY;arr[7][8]=Dam::ID_BLACK_DAM;arr[7][9]=Dam::ID_WHITE_EMPTY;
            arr[8][0]=Dam::ID_WHITE_EMPTY;arr[8][1]=Dam::ID_BLACK_DAM;arr[8][2]=Dam::ID_WHITE_EMPTY;arr[8][3]=Dam::ID_BLACK_DAM;arr[8][4]=Dam::ID_WHITE_EMPTY;arr[8][5]=Dam::ID_BLACK_DAM;arr[8][6]=Dam::ID_WHITE_EMPTY;arr[8][7]=Dam::ID_BLACK_DAM;arr[8][8]=Dam::ID_WHITE_EMPTY;arr[8][9]=Dam::ID_BLACK_DAM;
            arr[9][0]=Dam::ID_BLACK_DAM;arr[9][1]=Dam::ID_WHITE_EMPTY;arr[9][2]=Dam::ID_BLACK_DAM;arr[9][3]=Dam::ID_WHITE_EMPTY;arr[9][4]=Dam::ID_BLACK_DAM;arr[9][5]=Dam::ID_WHITE_EMPTY;arr[9][6]=Dam::ID_BLACK_DAM;arr[9][7]=Dam::ID_WHITE_EMPTY;arr[9][8]=Dam::ID_BLACK_DAM;arr[9][9]=Dam::ID_WHITE_EMPTY;
            wxPuts(wxT("d1\n"));
        }
        wxPuts(wxT("d3\n"));
        if (gametype==GamePanel::playervsai)
        {
            this->playername=playername;
            this->gametype=BoardPanel::ID_PLAYER_VS_AI;
            if (greedytype==greedybyfront)
            {
                wxPuts(wxT("greedy by front\n"));
                this->greedytype=BoardPanel::ID_GREEDY_BY_FRONT;
            }
            else if (greedytype==greedybyback)
            {
                this->greedytype==BoardPanel::ID_GREEDY_BY_BACK;
            }
        }
        else if (gametype==GamePanel::aivsai)
        {
            this->gametype=BoardPanel::ID_AI_VS_AI;
            if (greedytype1==greedybyfront)
            {
                this->greedytype1=BoardPanel::ID_GREEDY_BY_FRONT;
            }
            else if (greedytype1==greedybyback)
            {
                this->greedytype1=BoardPanel::ID_GREEDY_BY_BACK;
            }

            if (greedytype2==greedybyfront)
            {
                this->greedytype2=BoardPanel::ID_GREEDY_BY_FRONT;
            }
            else if (greedytype2==greedybyback)
            {
                this->greedytype2=BoardPanel::ID_GREEDY_BY_BACK;
            }

            if (gamespeed==slow)
            {
                this->gamespeed=BoardPanel::ID_SLOW;
            }
            else if (gamespeed==medium)
            {
                this->gamespeed=BoardPanel::ID_MEDIUM;
            }
            else if (gamespeed==fast)
            {
                this->gamespeed=BoardPanel::ID_FAST;
            }
        }

        boardpanel = new BoardPanel(this,wxID_ANY,boardsize,this->gametype,arr,this->greedytype,this->greedytype1,this->greedytype2,this->gamespeed);
//        BoardPanel(wxWindow*parent,int id,int boardsize,int gametype,int **arr,int greedytype,greedytype1,greedytype2,gamespeed);

        menugamepanel = new MenuGamePanel(this,wxID_ANY);
        wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
        hbox->Add(boardpanel,1,wxEXPAND|wxALL,0);
        hbox->Add(menugamepanel,1,wxALIGN_RIGHT,5);
        this->SetSizer(hbox);


    }
    else
    {

    }
    wxImage::AddHandler(new wxPNGHandler);
}

